package com.araaya.eslimsmobile;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.Toast;

import com.araaya.eslimsmobile.R;
import com.araaya.eslimsmobile.gps.MobileKmlWriter;
//import com.google.android.maps.GeoPoint;
//import com.google.android.maps.ItemizedOverlay;
//import com.google.android.maps.OverlayItem;

import java.util.ArrayList;
import java.util.HashMap;

public class MyItemizedOverlayAdjacentLand{ /*extends ItemizedOverlay {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	Context mContext;
	OverlayItem item;
	boolean res=false;

	public MyItemizedOverlayAdjacentLand(Drawable marker) {
		super(boundCenterBottom(marker));
	}

	public MyItemizedOverlayAdjacentLand(Drawable marker, Context context) {
		super(boundCenterBottom(marker));
		mContext = context;
	}

	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}	

	@Override
	protected boolean onTap(int i) {
		// when you tap on the marker this will show the informations provided
		// by you when you create in the
		// main class the OverlayItem
		
		 * OverlayItem item = mOverlays.get(i);
		 * 
		 * GeoPoint gpoint = item.getPoint(); double lat =
		 * gpoint.getLatitudeE6()/1e6; double lon = gpoint.getLongitudeE6()/1e6;
		 * String toast = "Title: "+item.getTitle(); toast +=
		 * "\nText: "+item.getSnippet(); toast +=
		 * "\nSymbol coordinates AdjacentLand: Lat = "
		 * +lat+" Lon = "+lon+" (microdegrees)";
		 * //Toast.makeText(MapOverlayDemo.context, toast,
		 * Toast.LENGTH_LONG).show();
		 * 
		 * 
		 * AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		 * dialog.setTitle(item.getTitle());
		 * //dialog.setMessage(item.getSnippet()); dialog.setMessage(toast);
		 * dialog.show();
		 

		adjacentMapAlert(mContext, i);
		
		call(true);


		return res;
	}

	private void adjacentMapAlert(final Context ctx, final int point) {

		try {

			item = mOverlays.get(point);
			
			

			GeoPoint gpoint = item.getPoint();
			final double lat = gpoint.getLatitudeE6() / 1e6;
			final double lon = gpoint.getLongitudeE6() / 1e6;
			// Toast.makeText(ctx, toast, Toast.LENGTH_LONG).show();
			String txt = "GPS Point : ";
			txt += " \n Lat : " + lat + " " + "\n Lon : " + lon + ""
					+ "\n\n Do you want to add this point?";

			AlertDialog.Builder alt_bld = new AlertDialog.Builder(ctx);
			alt_bld.setMessage(txt)
					.setCancelable(false)
					.setPositiveButton("Add Point",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {
									
									res=true;
									// Add point
									HashMap<String, String> map = new HashMap<String, String>();
									map.put("lon", "" + lon);
									map.put("lat", "" + lat);
									map.put("alt", "" + 0);
									KmlHome.pointList.add(map);

									String toast = "The Point is added.";
									toast += "\n coordinates AdjacentLand: Lat = "
											+ lat + " Lon = " + lon;

									Log.d("PointListSize=", ""
											+ KmlHome.pointList.size());
									toast += "\n Point List Size : "
											+ KmlHome.pointList.size();

									Toast.makeText(ctx, toast,
											Toast.LENGTH_LONG).show();
									
									
									return;

								}
							})

					.setNeutralButton("No",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {

									res=false;
									dialog.cancel();

									return;

								}
							});

			AlertDialog alert = alt_bld.create();
			alert.setTitle("Adjacent Map Point");
			// Icon for AlertDialog
			alert.setIcon(R.drawable.land);
			alert.show();
			
			

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	private void call(boolean r) {
		Drawable marker =mContext.getResources().getDrawable(R.drawable.marker);
		if(r){
			//change add point color
			marker = mContext.getResources().getDrawable(R.drawable.markergreen);
		    //Set its bounds
		    //marker.setBounds(0,0,marker.getIntrinsicWidth(),marker.getIntrinsicHeight());
			
		    
		    
		    
		}else{
			marker = mContext.getResources().getDrawable(R.drawable.marker);
			
		}
		
		int width = marker.getIntrinsicWidth();
		int height = marker.getIntrinsicHeight();
		marker.setBounds(-(width/2),-height,(width/2),0);
		
		//Set the new marker
	    item.setMarker(marker);
		
	}
*/
}
